<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <h2>axios的config模式</h2>
    <button class="get">get请求</button>
    <button class="post">post请求</button>
    <script src="./lib/axios.js"></script>
    <script>
      // 1. 测试get请求
      // 机器人聊天接口：http://ajax-api.itheima.net/api/robot
      axios.defaults.baseURL='http://ajax-api.itheima.net'
      document.querySelector('.get').onclick=()=>{
        axios({
          method:'get',
          url:'/api/robot',
          params:{
            spoken:'你是ikun吗',
          }
        }).then((res)=>{
          console.log(res);
        })
      }
      // 2.测试post请求 ：http://ajax-api.itheima.net/api/login
      // 账号：admin 密码：123456

      document.querySelector('.post').onclick=()=>{
        axios({
          method:'post',
          url:'/api/login',
          data:{
            username:'admin',
            password:'123456'
          }
        }).then((res)=>{
          console.log(res);
        })
      }
    </script>
  </body>
</html>
